package com.shop.controller;

import com.mybatisflex.core.paginate.Page;
import com.shop.entity.ShopOrderAddress;
import com.shop.service.ShopOrderAddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 订单收货地址 控制层。
 *
 * @author 彭新才
 * @since 2024-10-14
 */
@RestController
@Tag(name = "订单收货地址接口")
@RequestMapping("/shopOrderAddress")
public class ShopOrderAddressController {

    @Autowired
    private ShopOrderAddressService shopOrderAddressService;

    /**
     * 添加订单收货地址。
     *
     * @param shopOrderAddress 订单收货地址
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("save")
    @Operation(summary = "保存订单收货地址")
    public boolean save(@RequestBody @Parameter(description = "订单收货地址") ShopOrderAddress shopOrderAddress) {
        return shopOrderAddressService.save(shopOrderAddress);
    }

    /**
     * 根据主键删除订单收货地址。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("remove/{id}")
    @Operation(summary = "根据主键删除订单收货地址")
    public boolean remove(@PathVariable @Parameter(description = "订单收货地址主键") Serializable id) {
        return shopOrderAddressService.removeById(id);
    }

    /**
     * 根据主键更新订单收货地址。
     *
     * @param shopOrderAddress 订单收货地址
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("update")
    @Operation(summary = "根据主键更新订单收货地址")
    public boolean update(@RequestBody @Parameter(description = "订单收货地址主键") ShopOrderAddress shopOrderAddress) {
        return shopOrderAddressService.updateById(shopOrderAddress);
    }

    /**
     * 查询所有订单收货地址。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    @Operation(summary = "查询所有订单收货地址")
    public List<ShopOrderAddress> list() {
        return shopOrderAddressService.list();
    }

    /**
     * 根据订单收货地址主键获取详细信息。
     *
     * @param id 订单收货地址主键
     * @return 订单收货地址详情
     */
    @GetMapping("getInfo/{id}")
    @Operation(summary = "根据主键获取订单收货地址")
    public ShopOrderAddress getInfo(@PathVariable Serializable id) {
        return shopOrderAddressService.getById(id);
    }

    /**
     * 分页查询订单收货地址。
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("page")
    @Operation(summary = "分页查询订单收货地址")
    public Page<ShopOrderAddress> page(@Parameter(description = "分页信息") Page<ShopOrderAddress> page) {
        return shopOrderAddressService.page(page);
    }

}
